package com.helper;

import java.io.IOException;

import com.dao.DaoMaster;
import com.dao.DaoSession;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class DbAdaptor   {

	private SQLiteDatabase db;
	public static DaoMaster daoMaster;
	public static DaoSession daoSession;
	private BdHelper bdHelper;

	/**
	 * Constructor send a reference to
	 * Bdhelper object. Instantiate 2 objects (DaoMaster,Bdhelper) and open the SQLiteDatabase
	 * 
	 * @param context
	 * @throws IOException
	 */
	public DbAdaptor(Context context) {
		try {

			bdHelper = new BdHelper(context);
			db = bdHelper.openDataBase();
			daoMaster = new DaoMaster(db);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	/** This method return DaoMaster Object **/
	public DaoMaster getDaoMaster() {

		return daoMaster;
	}
	/** This method return DaoSession Object **/
	public static DaoSession getSession() {
		daoSession = daoMaster.newSession();
		return daoSession;
	}

	/** This method return SQLiteDatabase Object **/
	public SQLiteDatabase getDb() {
		return db;
	}
	public BdHelper getHelper() {
		return bdHelper;
	}
}
